<template>
	<el-dialog
		:title="titleMap[mode]"
		v-model="visible"
		:width="500"
		destroy-on-close
		@closed="$emit('closed')"
	>
		<el-form
			:model="form"
			:rules="rules"
			ref="dialogForm"
			label-width="70px"
		>
			<el-row>
				<el-col :span="24">
					<el-form-item label="名称" prop="name">
						<el-input v-model="form.name"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="备注" prop="remark">
						<el-input v-model="form.remark"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>

		<sc-VxeTable
			:tablecode="'pro_repairreason_save'"
			:data="form.details"
			:gridOps="gridOpts"
			ref="subbe"
			:sortable="true"
		>
		</sc-VxeTable>

		<!-- </sc-water-mark> -->
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()"
				>保 存</el-button
			>
		</template>
	</el-dialog>
</template>

<script>
import skDicSelect from "@/components/skDicSelect";
import skAutoChoose from "@/components/skAutoChoose";
// import XEUtils from "xe-utils";
export default {
	emits: ["success", "closed"],
	components: { skAutoChoose, skDicSelect },
	data() {
		return {
			mode: "add",
			form: {
				details: [],
			},
			gridOpts: {
				height: 300,
			},
			titleMap: {
				add: "新增",
				edit: "编辑",
			},
			rules: {
				name: { required: true, message: "复修原因必填" },
			},
			visible: false,
			isSaveing: false,
		};
	},

	mounted() {},
	methods: {
		open(mode = "add") {
			this.mode = mode;
			this.visible = true;
			return this;
		},
		//表单提交方法
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = await this.$API.pro.repairreason.save.post(
						this.form
					);
					this.isSaveing = false;
					if (res.code == 200) {
						this.visible = false;
						this.$emit("success");
						this.$message.success("操作成功");
					}
				}
			});
		},

		//表单注入数据
		setData(data) {
			Object.assign(
				this.form,
				this.$TOOL.objCopy(this.$TOOL.removeNull(data))
			);
		},
	},
};
</script>

<style>
.attachments .el-upload--picture-card,
.attachments .el-upload-list--picture-card .el-upload-list__item {
	width: 100px;
	height: 100px;
	overflow: hidden;
}
</style>
